package com.mdjnu.mapper;

import com.mdjnu.pojo.Videos;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface VideoMapper {
    @Insert("insert into Videos(title, description, upload_time, duration, view_count, like_count, dislike_count, comment_count, user_id, cover_url, category_id, status, video_url) " +
            "values(#{title}, #{description}, #{uploadTime}, #{duration}, #{viewCount}, #{likeCount}, #{dislikeCount}, #{commentCount}, #{userId}, #{coverUrl}, #{caugoryId}, #{status}, #{videoUrl})")
    int insert(Videos videos);
    @Select("select * from Videos where user_id=#{userId} limit #{pageNum},#{pageSize}")
    List<Videos> findByUserId(int userId,int pageNum,int pageSize);
    @Select("select * from Videos limit #{pageNum},#{pageSize}")
    List<Videos> findAllByPage(int pageNum,int pageSize);
    @Select("select * from Videos where video_url=#{videoUrl}")
    Videos findById(int videoId);
    @Select("select * from Videos where status=#{status} limit #{stater},#{pageSize}")
    List<Videos> findByStantus(int stater,int pageSize,int status);
    /**
     *  查询最新视频
     * @param stater    起始位置
     * @param pageSize 每页视频数量
     * @param status   视频状态
     * @return  查询结果
     */
    @Select("select * from Videos where status=#{status} order by upload_time desc limit #{stater},#{pageSize}")
    List<Videos> findNewVideo(int stater,int pageSize,int status);
    /**
     *  查询最热视频
     * @param stater   起始位置
     * @param pageSize 每页视频数量
     * @param status   视频状态
     * @return 查询结果
     */
    @Select("select * from Videos where status=#{status} order by like_count desc limit #{stater},#{pageSize}")
    List<Videos> findHotVideo(int stater,int pageSize,int status);
    /**
     *  查询分类视频
     * @param categoryId 分类id
     * @param stater     起始位置
     * @param pageSize   每页视频数量
     * @param status     视频状态
     * @return  查询结果
     */
    @Select("select * from Videos where category_id=#{categoryId} and status=#{status} limit #{stater},#{pageSize}")
    List<Videos> findByCategoryId(int categoryId,int stater,int pageSize,int status);
    /**
     *  查询浏览量视频
     * @param stater     起始位置
     * @param pageSize   每页视频数量
     * @param status     视频状态
     * @return  查询结果
     */
    @Select("select * from Videos where status=#{status} order by view_count desc limit #{stater},#{pageSize}")
    List<Videos> findByViewCount(int stater,int pageSize,int status);
    /**
     *  查询评论量视频
     * @param stater     起始位置
     * @param pageSize   每页视频数量
     * @param status     视频状态
     * @return  查询结果
     */
    @Select("select * from Videos where status=#{status} order by comment_count desc limit #{stater},#{pageSize}")
    List<Videos> findByCommentCount(int stater,int pageSize,int status);
    @Select("select * from Videos where video_id=#{videoId}")
    Videos findByVideoId(int videoId);
}
